package com.example.mall.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.TextView
import com.example.mall.R
import com.example.mall.entity.User


class UserListAdapter(var mContext: Context, var mUserList: List<User>) : BaseAdapter() {



    override fun getCount(): Int {
        return mUserList.size
    }

    override fun getItem(position: Int): Any {
        return mUserList.get(position)
    }

    override fun getItemId(position : Int): Long {
        return position.toLong()
    }

    override fun getView(positon: Int, convertView: View?, parent: ViewGroup?): View {
        var holder : ViewHolder? =null
        var view = convertView
        if(view == null) {
            view = LayoutInflater.from(mContext).inflate(R.layout.item_list,null)
            holder = ViewHolder()
            holder.tv_phone = view.findViewById<TextView>(R.id.tv_phone)
            view.tag = holder
        }else{
            holder = view.getTag() as ViewHolder

        }

        val user = mUserList.get(positon)

        holder.tv_phone?.setText(user.phone)

        return view!!
    }

    class ViewHolder(
        var tv_phone : TextView? = null,

    )

}